#include "Entity.h"
#include "ForceGeneratorDrag.h"
#include "Vector3.hpp"

ForceGeneratorDrag::ForceGeneratorDrag(float coeffSimple, float coeffSquare) : ForceGenerator(), coeffSimple(coeffSimple), coeffSquare(coeffSquare)
{	}

ForceGeneratorDrag::~ForceGeneratorDrag()
{	}

void ForceGeneratorDrag::Update(int id, float time)
{
	//Calculate drag if particle is registered
	if (entityRegister->find(id) != entityRegister->end())
	{
		Vector3* velo = new Vector3(*((*entityRegister)[id]->Velocity()));
		float dragCoeff = velo->Magnitute();
		if (dragCoeff == 0) return;

		dragCoeff = (coeffSimple * dragCoeff) + (coeffSquare * dragCoeff * dragCoeff);
		
		velo->Normalize();
		(*velo) *= -dragCoeff;

		(*entityRegister)[id]->AddForce(*velo);
	}
}